package com.telpoo.frame.ui;

import java.util.ArrayList;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.widget.Toast;

import com.telpoo.frame.R;
import com.telpoo.frame.model.BaseModel;
import com.telpoo.frame.model.ModelListener;

public class BaseFragment extends Fragment implements ModelListener {

	public ProgressDialog loadingProgress;
	public boolean mIsBound;

	// public HomeActivity homeActivity;
	@Override
	public void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		// homeActivity = (HomeActivity) this.getActivity();
	}

	@Override
	public void onStart() {
		super.onStart();
	}

	@Override
	public void onResume() {
		super.onResume();
	}

	@Override
	public void onPause() {
		super.onPause();
	}

	@Override
	public void onStop() {
		super.onStop();
	}

	@Override
	public Context getContext() {
		return this.getActivity().getApplicationContext();
	}

	protected BaseModel getModel() {
		return BaseActivity.model;
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		return false;
	}

	public boolean onBackPressed() {
		return false;
	}

	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		// Fragment fragment =
		// getActivity().getSupportFragmentManager().findFragmentById(R.id.realtabcontent);
		// fragment.onActivityResult(requestCode, resultCode, data);
	}

	public void showToast(String message) {
		if (message != null)
			Toast.makeText(getContext(), "" + message, Toast.LENGTH_SHORT)
					.show();
		// else Toast.makeText(getContext(), "Null msg",
		// Toast.LENGTH_SHORT).show();
	}

	public void showToastMessage(int resId) {
		Toast.makeText(getContext(), getString(resId), Toast.LENGTH_LONG)
				.show();
	}

	public void showProgressDialog(Context context, String message) {
		closeProgressDialog();
		// loadingProgress = DialogUtils.progressDialogWaitingCustom(this,
		// message);

		loadingProgress = new ProgressDialog(context);
		loadingProgress.setMessage(message);
		loadingProgress.setCanceledOnTouchOutside(false);
		loadingProgress.show();
	}

	public void showProgressDialog(Context context) {
		closeProgressDialog();
		// loadingProgress = DialogUtils.progressDialogWaitingCustom(this,
		// message);

		loadingProgress = new ProgressDialog(context);
		loadingProgress.setMessage(getString(R.string.loading));
		loadingProgress.setCanceledOnTouchOutside(false);
		loadingProgress.show();
	}

	public void closeProgressDialog() {
		if (loadingProgress != null) {
			if (loadingProgress.isShowing())
				loadingProgress.dismiss();
			loadingProgress = null;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.telpoo.frame.model.ModelListener#onSuccess(int,
	 * java.util.ArrayList, java.lang.String)
	 */
	@Override
	public void onSuccess(int taskType, ArrayList<?> list, String msg) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.telpoo.frame.model.ModelListener#onFail(int, java.lang.String)
	 */
	@Override
	public void onFail(int taskType, String msg) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.telpoo.frame.model.ModelListener#onProgress(int, int)
	 */
	@Override
	public void onProgress(int taskType, int progress) {
		// TODO Auto-generated method stub

	}

}
